/**
 * Project Name:gc.sms.mvn
 * File Name:EmployeeDaoImpl.java
 * Package Name:com.clps.dev.sms.dao.impl
 * Date:2018-11-27 16:36:38
 * Copyright (c) 2018,http://www.clpsglobal.com/zh/home-cn/ All Rights Reserved.
 *
 */
package com.clps.dev.sms.dao.sm.impl;


import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.clps.dev.sms.common.dao.impl.BaseDaoImpl;
import com.clps.dev.sms.dao.sm.EmployeeDao;
import com.clps.dev.sms.entity.sm.Employee;

/**
 * 
 * ClassName: EmployeeDaoImpl <br/>
 * Description: 
 *
 * @author Jack.Huang
 * @version V1.0
 * @since JDK 1.8
   @date:2018-11-27 16:36:38
 */
@Repository
public class EmployeeDaoImpl extends BaseDaoImpl<Employee> implements EmployeeDao{
	
	private static final String HQL_QUERY_EMAIL = "from Employee where empeMail = ?";
	
	public EmployeeDaoImpl() {
		super(Employee.class);
	}

	/**
	 * 
	 * @see com.clps.dev.sms.dao.sm.EmployeeDao#queryByEmail(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Employee> queryByEmail(String email) {
		List<Employee> list = (List<Employee>) this.getHibernateTemplate().find(HQL_QUERY_EMAIL, email);
		return list;
	}

	/**
	 * 
	 * @see com.clps.dev.sms.dao.sm.EmployeeDao#findByPageOrderByTime(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Employee> findByPageOrderByTime(Integer begin, Integer pageSize, String createtime, String empName,
			Integer status, Integer position) {
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Employee.class);
		if(empName!=null) {
			detachedCriteria.add(Restrictions.like("empName", "%"+empName+"%"));
		}
		if(status!=null) {
			detachedCriteria.add(Restrictions.like("empStatus", "%"+status+"%"));
		}
		if(position!=null) {
			detachedCriteria.add(Restrictions.like("empPositionId", "%"+position+"%"));
		}
		detachedCriteria.setProjection(null);
		detachedCriteria.addOrder(Order.asc(createtime));
		return (List<Employee>) this.getHibernateTemplate().findByCriteria(detachedCriteria, begin, pageSize);
	}
}
